<template>
  <div>
    <div class="section-title">
      <h2>推荐歌单</h2>
      <span class="more">更多</span>
    </div>
    <div class="recommend-playlists-container">
      <div class="recommend-playlists">
        <div 
          v-for="playlist in playlists" 
          :key="playlist.content_id" 
          class="playlist-item"
          @click="goToSonglistDetail(playlist.content_id)"
        >
          <img :src="playlist.cover" :alt="playlist.title">
          <h3>{{ playlist.title }}</h3>
          <p>{{ playlist.desc }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { musicApi } from '@/api/music'

const router = useRouter()
const playlists = ref([])

const goToSonglistDetail = (id) => {
  router.push(`/songlist/${id}`)
}

onMounted(async () => {
  try {
    const response = await musicApi.getRecommendPlaylists()
    playlists.value = response.data.data.list || []
  } catch (error) {
    console.error('获取推荐歌单失败:', error)
  }
})
</script>

<style lang="scss" scoped>
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 15px 0 8px;  // 减小标题的上下间距
  
  h2 {
    font-size: 16px;  // 减小标题字号
    font-weight: 600;
    margin: 0;
  }
  
  .more {
    color: #999;
    font-size: 12px;  // 减小更多链接的字号
  }
}

.recommend-playlists-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; // 增强iOS滚动体验
  scrollbar-width: none; // 隐藏Firefox滚动条
  
  &::-webkit-scrollbar {
    display: none; // 隐藏Chrome滚动条
  }
}

.recommend-playlists {
  display: flex;
  flex-wrap: nowrap;
  padding: 4px 0;
  gap: 10px;  // 项目之间的间距
}

.playlist-item {
  flex: 0 0 auto;
  width: 30%; // 设置每个项目的宽度
  min-width: 100px; // 最小宽度
  max-width: 140px; // 最大宽度
  cursor: pointer;
  transition: transform 0.2s;

  &:hover {
    transform: translateY(-3px);  // 减小悬停效果的位移
  }

  img {
    width: 100%;
    aspect-ratio: 1;  // 保持图片为正方形
    object-fit: cover;  // 确保图片填充
    border-radius: 6px;  // 减小圆角
    margin-bottom: 4px;  // 减小图片底部间距
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);  // 添加轻微阴影
  }

  h3 {
    font-size: 12px;  // 减小标题字号
    margin: 3px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 2px;  // 添加文字两侧内边距
  }

  p {
    font-size: 10px;  // 减小描述文字字号
    color: #999;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.3;  // 调整行高
    padding: 0 2px;  // 添加文字两侧内边距
    margin: 0;  // 移除默认外边距
  }
}
</style>